package com.asp.alumnisystem.adapter;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.asp.alumnisystem.R;
import com.asp.alumnisystem.base.IRefreshView;
import com.asp.alumnisystem.model.UserModel;
import com.asp.alumnisystem.ui.PersonalActivity;
import com.asp.alumnisystem.utils.UiUtils;
import com.bumptech.glide.Glide;

/**
 * 首页好友详情中显示好友列表的adapter
 */
public class FriendListAdapter extends AspBaseAdapter<UserModel> {

    private DelFriendListener listener;

    public FriendListAdapter(IRefreshView refreshView, DelFriendListener listener) {
        super(refreshView);
        this.listener = listener;
    }

    @Override
    protected int getItemLayoutId(int type) {
        return R.layout.friend_list_item_layout;
    }

    @Override
    protected void bindView(RViewHolder viewHolder, final int position, final UserModel model) {
        Glide.with(viewHolder.itemView.getContext()).load(model.getIconPath()).into((ImageView) viewHolder.getView(R.id.image_view));
        viewHolder.setText(R.id.name_view, model.getNickName());
        viewHolder.setText(R.id.class_view, model.getCompany());
        viewHolder.setItemOnClick(R.id.del_view, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.delFriendClick(position, model);
            }
        });

        //点击头像今进入个人中心
        viewHolder.setItemOnClick(viewHolder.itemView, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putSerializable("model", model);
                bundle.putSerializable("isFriend", true);
                UiUtils.jumpToPage(v.getContext(), PersonalActivity.class, bundle);
            }
        });
    }

    public interface DelFriendListener{
        void delFriendClick(int position, UserModel model);
    }
}
